/**
 * 用户详情对话框
 */
var InfoDlg = {
    data: {
        deptId: "",
        deptName: ""
    }
};

layui.use(['layer', 'form', 'admin', 'laydate', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var layer = layui.layer;

    // 点击部门时
    $('#deptName').click(function () {
        var formName = encodeURIComponent("parent.InfoDlg.data.deptName");
        var formId = encodeURIComponent("parent.InfoDlg.data.deptId");
        var treeUrl = encodeURIComponent("/system/dept/deptTreeList");

        layer.open({
            type: 2,
            title: '部门选择',
            area: ['90%', '90%'],
            content: Lu.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#deptId").val(InfoDlg.data.deptId);
                $("#deptName").val(InfoDlg.data.deptName);
            }
        });
    });

    // 添加表单验证方法
    form.verify({
        psw: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'],
        repsw: function (value) {
            if (value !== $('#userForm input[name=password]').val()) {
                return '两次密码输入不一致';
            }
        }
    });

    // 渲染时间选择框
    laydate.render({
        elem: '#birthday'
    });

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Lu.ctxPath + "/system/user/update", function (data) {
            admin.putTempData('msg', '修改成功!');
            admin.putTempData('formOk', true);
            admin.closeThisDialog();
        }, function (data) {
            Lu.error("修改失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
        return false;
    });
});